<template>
  <div>
    <h1>当前求和为：{{sum}}</h1>
    <h3>当前求和放大10倍为：{{bigSum}}</h3>
    <h3>我在{{school}}学习{{ subject }}</h3>
    <select v-model="n">
      <option :value="1">1</option>
      <option :value="2">2</option>
      <option :value="3">3</option>
    </select>
    <button @click="ADD(n)">+</button>
    <button @click="subtraction(n)">-</button>
    <button @click="additionOdd(n)">当前求和为奇数再加</button>
    <button @click="addWait(n)">等一等再加</button>
  </div>
</template>

<script>
import { mapState } from 'vuex'
import { mapGetters } from 'vuex'
import { mapActions } from 'vuex'
import { mapMutations } from 'vuex'
export default {
    name:'Count',
    data(){
      return{
        n:1,

      }
    },
    methods:{
      // addition(){
      //   // this.sum += this.n;
      //   this.$store.commit('ADD',this.n)
      // },
      // subtraction(){
      //   // this.sum -= this.n;
      //   this.$store.commit('REDUCE',this.n)
      // },

      ...mapMutations({addition:'ADD',subtraction:'REDUCE'}),
      ...mapMutations(['ADD','REDUCE']),
      /**************************************/
      // additionOdd(){
      //     this.$store.dispatch('addOdd',this.n)
      // },
      // additionWait(){
      //     this.$store.dispatch('addWait',this.n)
      // },

      ...mapActions({additionOdd:'addOdd',additionWait:'addWait'}),
      ...mapActions(['addOdd','addWait'])

    },
    computed:{
      //自己手写计算属性
      // sum(){
      //   return this.$store.state.sum
      // },
      // subject(){
      //   return this.$store.state.subject
      // },
      // school(){
      //   return this.$store.state.school
      // },
      //借助mapstate生成
      // ...mapState({sum:'sum',school:'school',subject:'subject'}),
      ...mapState(['sum','school','subject']),

      // bigSum(){
      //   return this.$store.getters.bigSum
      // },
      ...mapGetters({bigSum:'bigSum'}),
      // ...mapGetters(['bigSum'])
    },
    mounted(){
      // const x = mapState({sum:'sum',school:'school',xueke:'xueke'})
      // console.log(x);
    }
}
</script>

<style>
  button{
    margin-left: 5px;
  }
</style>